
EditSettings:
	run, *edit %USER_SETTINGS%
return


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;MOUSE MOVE FUNCTION - HOVER FUNCTION

WM_MOUSEMOVE()
{
	global USER_INI
	
	MouseGetPos,,, winHwnd, ctrlHwnd, 2
	ControlGetText, ctrlName, %ctrlHwnd%
	
	
	if (lastHwnd = controlhwnd)
		return
	
	bColor := USER_INI.Colors[nospace(NAME) "ButtonColor"] ? USER_INI.Colors[nospace(NAME) "ButtonColor"] : USER_INI.Colors.ButtonColor
	tColor := USER_INI.Colors[nospace(NAME) "TextColor"] ? USER_INI.Colors[nospace(NAME) "TextColor"] : USER_INI.Colors.TextColor
	bHColor := USER_INI.Colors[nospace(NAME) "HLButtonColor"] ? USER_INI.Colors[nospace(NAME) "ButtonColor"] : USER_INI.Colors.ButtonColor
	tHColor := USER_INI.Colors[nospace(NAME) "HLTextColor"] ? USER_INI.Colors[nospace(NAME) "TextColor"] : USER_INI.Colors.TextColor
	
	
	if (ctrlName = "backsearch" || ctrlHwnd = "" || ctrlName = "FOOTER" || !instr(ctrlHwnd, "static"))
	{
		CTLCOLORS.Attach(lastHwnd, bColor, tCOlor)
		lastHwnd := ""
		return
	}
	
	CTLCOLORS.Attach(lastHwnd, bColor, tColor)
	CTLCOLORS.Change(controlhwnd, USER_INI.Colors.ButtonColor, USER_INI.Colors.TextColor)
	
	lastHwnd := controlhwnd
}


/*!
	Class: Button
		Simple object that provides a simple and 
		dynamic method of getting button properties.
*/
class CButton
{
	
	__New(name="")
	{
		if (name)
		{
			this.Name := name
		}
	}
	
	/*!
		Property: BackColor [get/set]
			Gets or sets the current button's back color.
		
		Value:
			The property to get or set.
	*/
	__Get(what)
	{	
		return USER_SETTINGS[(this.Name what)] ? USER_SETTINGS[(this.Name what)] : USER_SETTINGS[what]	
	}
	
	__Set(what, params*)
	{
		for ind, val in params
			listVar .= (listVar ? "`n" : "") %add%
	}
}
/*!
	End of class
*/



/*!
	Function: ON_LEFT(CONTROL_POSX)
		Determine the relative location of the mouse (left or right) based on the main GUI's midpoint.

	Parameters:
		CONTROL_POSX - A coordinate representing the left-most x-coordinate of a GUI component					   

	Returns: Either true or false (1 or 0), based on the GUI component's relative position.
	
			 True - The component is on the *left* of the main GUI
			 False - The component is on the *right* of the main GUI
*/
ON_LEFT(CONTROL_POSX)
{
	global
	
	MIDPOINT := ((2 * BUTTON_WIDTH) + (3 * GUI_SPACING)) / 2
	
	if (CONTROL_POSX < MIDPOINT)
		return 1
	else
		return 0
}


/*!
	Function: Google(GSEARCH)
		Opens a browser with the given search text results from a Google search.

	Parameters:
		GSEARCH - The search text.
*/
Google(GSEARCH)
{
	GSEARCH := RegExReplace(GSEARCH, "i)\s", "+")
	GSEARCH := "http://www.google.com/search?hl=en&source=hp&q=" GSEARCH "&aq=f&aqi=&aql=&oq="
	Run % GSEARCH
}




GetModifiers()
{
	 Modifiers := GetKeyState("Ctrl", "P") ? "^" : ""
	 Modifiers .= GetKeyState("Alt", "P") ? "!" : ""
	 Modifiers .= GetKeyState("Shift", "P") ? "+" : ""
	 Modifiers .= GetKeyState("LWin", "P") ? "#" : ""
 
	Return, Modifiers
}




Execute(Command)
{
	If !Command ; if command is blank
		Return
	
	COMMAND := RegExReplace(COMMAND, "\s+", A_Space) ; Deletes duplicated spaces and tabs
	RegExMatch(COMMAND, ";\K.+?$", Description) ; Extracts the description if there is one
	COMMAND := RegExReplace(COMMAND, ";" Description "$") ; Removes the description from the command
	COMMAND := Trim((Description && ReturnDescription) ? Description : COMMAND)
	
	Transform, Command, Deref, % Command
	
	;~~~~~~~~~~~~~~~~~~~~~~
	;[F] FUNCTION AS ACTION
	
		If (RegExMatch(Command, "i)^\[F\]\s*(?P<Func>\w+)(\(\s*(?P<Params>.+?)\s*\)$)?", m) && IsFunc(mFunc))
		{
			If mParams
			{
				Loop, Parse, mParams, CSV
					param%A_Index% := Trimmer(A_LoopField)
			}
			
			%mFunc%(param1, param2, param3, param4, param5, param6, param7, param8, param9, param10)
			Gui, 1:Destroy ; destroy all guis
		}
	
	;~~~~~~~~~~~~~~~~~~~
	;[L] LABEL AS ACTION
	
		Else If (RegExMatch(Command, "i)^\[L\]\s*\K.+", Label) && IsLabel(Label))
		{
			Gui, 1:Destroy ; destroy all guis
			Gosub, %LABEL%
		}
		
	;~~~~~~~~~~~~~~~~~~~~~~
	;[S] SHORTCUT AS ACTION
	
		Else If RegExMatch(COMMAND, "i)^\[S\]\s*\K.+", SHORTCUT)
		{
			Gui, 1:Destroy ; destroy all guis
			SendInput, {Blind}%SHORTCUT%
		}
		
	;~~~~~~~~~~~~~~~~~~~
	;[M] MACRO AS ACTION
	
		Else If RegExMatch(Command, "i)^\[M\]\s*\K.+", MACRO)
		{
			Gui, 1:Destroy ; destroy all guis
			MACRO .= "`n`nsleep, 50`n`nExit App"
			FileDelete, tmpMacroFile.ahk
			FileAppend, %Macro%, tmpMacroFile.ahk
			RunWait, tmpMacroFile.ahk`
		}
	
	;~~~~~~~~~~~~~~~~~~
	;[T] TEXT AS ACTION
		
		Else If RegExMatch(Command, "i)^\[T\]\s*\K.+", TEXT)
		{
			Gui, 1:Destroy ; destroy all guis
			StringReplace, TEXT, TEXT, ``n, `n, All
			StringReplace, TEXT, TEXT, ``r, `r, All
			StringReplace, TEXT, TEXT, ``t, %A_Tab%, All
			SendInput, {Raw}%TEXT%
		}
		
	;~~~~~~~~~~~~~~~~~~~~~~
	;[G] SIDE GUI AS ACTION
		
		else if RegExMatch(Command, "i)^\[G\]\s*\K.+", NEWGUI)
			SIDE_GUI(NEWGUI)
			
	;~~~~~~~~~~~~~~~~~~~~~
	;[P] PROGRAM AS ACTION
	
		else if RegExMatch(Command, "i)^\[P\]\s*\K.+", THE_PROGRAM)
		{
			Gui, 1:Destroy ; destroy all guis
			SetTitleMatchMode, 2
			
			THE_PROGRAM_NOEXT := RegExReplace(THE_PROGRAM, "i).exe")

			IfWinExist % THE_PROGRAM_NOEXT ; check if it exists already
				WinActivate % THE_PROGRAM_NOEXT
			else
				Run % THE_PROGRAM
			
			SetTitleMatchMode, 1
		}
		
	;~~~~~~~~~~~~~~~~~~~~~
	;[E] EXPLORE AS ACTION
	
		else if RegExMatch(Command, "i)^\[E\]\s*\K.+", EXPLORE_PATH)
		{
			Gui, 1:Destroy
			run, explore %EXPLORE_PATH%
		}
		
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	;[AHK] EDIT AHK WITH AHK EDITOR
	
	
		else if RegExMatch(Command, "i)^\[AHK\]\s*\K.+", AHK_PATH)
		{
			Gui, 1:Destroy
			AHK(AHK_PATH)
		}
			
	;~~~~~~~~~~~
	;RUN ACTION
	
		Else
		{
			Gui, 1:Destroy ; destroy all guis
			Run(Command)
		}
}



AHK(AHK_PATH)
{
	Run, *edit `"%AHK_PATH%`"
}



Trimmer(str, omitchars=" `t")
{ ; Allow to use Trim() with AutoHotkey basic
	If !StrLen(omitchars)
		Return, str
	str := RegExReplace(str, "^[" omitchars "]+") ; Trims from the beginning
	str := RegExReplace(str, "[" omitchars "]+$")	; Trims from the end
	Return, str
}


;~~~~~~~~~~~~
;RUN FUNCTION

Run(Path)
{
	Run, % Path,, UseErrorLevel
	If ErrorLevel
		MsgBox, 262160, Run :, Error with this command!`n%Path%, 1
}


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;GET NO RUN APPS FROM INI FILE

NO_RUNS(USER_SETTINGS)
{
	USER_INI := new ini(USER_SETTINGS)
	NORUN_KEYS := USER_INI.Keys("NORUN")
	loop, parse, NORUN_KEYS, `n
	{
		TEMP_VAR := USER_INI.NORUN[A_LoopField]
		GroupAdd, NORUN, %TEMP_VAR%
	}
	return, NORUN
}

